package com.test14_枚举;

import org.junit.Test;


/**
 * 枚举：JDK1.5之后引入
 * 继承Enum类
 */
public class YootkDemo_01 {

    @Test
    public void test1() {
        Color c = Color.RED;
        System.out.println(c);
    }

    @Test
    public void test2() {
        // 遍历全部枚举信息
        for (Color c : Color.values()) {
            System.out.println(c);
        }
    }

    @Test
    public void test3() {
        // JDK1.5开始，switch支持枚举
        Color c = Color.BLUE;
        switch (c) {
            case RED:
                System.out.println("【RED】红色");
                break;
            case GREEN:
                System.out.println("【GREEN】绿色");
                break;
            case BLUE:
                System.out.println("【BLUE】蓝色");
                break;
        }
    }

    @Test
    public void test4() {
        for (Color c : Color.values()) {
            System.out.println("【" + c + "】 name = " + c.name() + ", ordinal = " + c.ordinal());
        }
    }
}

enum Color {
    RED, GREEN, BLUE;
}
